package com.lxinet.jeesns.modules.wechat.service.impl;

import com.lxinet.jeesns.core.dto.ResponseModel;
import com.lxinet.jeesns.core.entity.Page;
import com.lxinet.jeesns.modules.wechat.dao.IWechatAutoReplyDao;
import com.lxinet.jeesns.modules.wechat.entity.WechatAutoReply;
import com.lxinet.jeesns.modules.wechat.entity.WechatReplyConfig;
import com.lxinet.jeesns.modules.wechat.service.IWechatAutoReplyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lzs on 2017/4/11.
 */
@Service("wechatAutoReplyService")
public class WechatAutoReplyServiceImpl implements IWechatAutoReplyService{

    @Resource
    private IWechatAutoReplyDao wechatAutoReplyDao;

    @Override
    public WechatAutoReply findByKey(String key, String wxuin) {
        return wechatAutoReplyDao.findByKey(key,wxuin);
    }

    @Override
    public WechatAutoReply findById(Integer id) {
        return wechatAutoReplyDao.findById(id);
    }

    @Override
    public List<WechatAutoReply> getAllByWXuin(String wxuin) {
        return wechatAutoReplyDao.getAllByWXuin(wxuin);
    }

    @Override
    public ResponseModel listByPage(Page page, String wxuin) {
        List<WechatAutoReply> list = wechatAutoReplyDao.listByPage(page,wxuin);
        ResponseModel model = new ResponseModel(0,page);
        model.setData(list);
        return model;
    }

    @Override
    public ResponseModel delete(Integer id) {
        WechatAutoReply wechatReplyConfig = this.findById(id);
        if(wechatReplyConfig == null){
            return new ResponseModel(-1,"配置不存在");
        }
        int result = wechatAutoReplyDao.delete(id);
        if(result == 1){
            return new ResponseModel(1,"删除成功");
        }
        return new ResponseModel(-1,"删除失败");
    }

    @Override
    public int save(WechatAutoReply wechatAutoReply) {
        return wechatAutoReplyDao.save(wechatAutoReply);
    }


    @Override
    public int update(WechatAutoReply wechatAutoReply) {
        return wechatAutoReplyDao.update(wechatAutoReply);
    }
}
